<%-- 
    Document   : index
    Created on : Oct 19, 2009, 5:09:33 AM
    Author     : neo
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/jsrpc.tld" prefix="jsrpc"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<jsrpc:broker>
    <jsrpc:register id="serviceLocator" bean="org.workforce.service.ServiceLocator"/>
    <jsrpc:register id="systemSession" bean="org.workforce.service.SystemSessionBean"/>
</jsrpc:broker>
<html>
    <head>
        <title>Login Workforce</title>
        <jsrpc:script/>
        <script language=javascript type="text/javascript">
            function initPage() {
                
            
            <%
            //String s = this.
            String s = request.getServletPath();
            System.out.println("login.jsp[" + s + "]");
            String sp[] = s.split("/");
            System.out.println("size:" + sp.length);
            StringBuffer sf = new StringBuffer();
            for (int i = 2; i < sp.length; i++) {
                //System.out.println("["+ sp[i]+"]");
                sf.append("../");
            }
            session.setAttribute("BACK_PATH", sf.toString());
            sf.append("BROKER-REGISTER");
            System.out.println("path[" + sf.toString() + "]");
            %>
                    initBroker("<%=sf.toString()%>");
                    setVisible(true);
                }
                function icon_point(thisFrom) {
                    thisFrom.style.cursor = "pointer";
                }
                function login() {
                    setVisible2(true);
                    var user = {
                        "javaClass": "org.workforce.vo.User",
                        "userId": document.getElementById("userid").value,
                        "password": document.getElementById("password").value
                    };
                
                    var chk = systemSession.login(user);
                    if( chk == "false" ) {
                        alert("Cannot Login to system!\nPlease contract administrator.");
                        setVisible2(false);
                        setVisible(true);
                    } else {
                        //alert("Can Login to system.");
                        setVisible2(false);
                        setVisible(true);
                        window.location.href = "pages/mainPanel.jsp";
                    }
                }
                function setVisible( setting )
                {

                    var width =  window.innerWidth;
                    var height = window.innerHeight;
                    //alert("w:"+ width+" H:"+ height);
                    var myElement = document.getElementById("loginForm");
                    var left = ((width/2) - (300/2));
                    var top = ((height/2) - (160/2));
                    if(setting) {
                        myElement.style.visibility="visible";
                        myElement.style.top = top + "px";
                        myElement.style.left = left + "px";
                    
                        //setVisible2(false);
                    } else {
                        myElement.style.visibility="hidden";
                        //setVisible2(true);
                    }
                }
                function setVisible2( setting )
                {

                    var width =  window.innerWidth;
                    var height = window.innerHeight;
                    //alert("w:"+ width+" H:"+ height);
                    var myElement = document.getElementById("waiting");
                    var left = ((width/2) - (300/2));
                    var top = ((height/2) - (160/2));
                    if(setting) {
                        myElement.style.color = "#f5f5f5";
                        myElement.style.visibility="visible";
                        myElement.style.top = top + "px";
                        myElement.style.left = left + "px";
                        document.getElementById("loginForm").style.visibility="hidden";
                    } else {
                        myElement.style.visibility="hidden";
                    }
                    document.bgColor = "#f5f5f5";
                }
        </script>
        <script language="JavaScript" type="text/javascript" src="js/util.js"></script>
    <style type="text/css">

        #loginForm {
            background-color: white;
            position: absolute;
            height:160px;
            width:300px;
            left:200px;
            top:150px;
            visibility: hidden
        }
        #waiting {
            background-color: #f5f5f5;
            position: absolute;
            height:160px;
            width:300px;
            left:200px;
            top:150px;
            visibility: hidden;
            font-style: italic;
            font-size: large;
            font-family: sans-serif;
            font-weight: bold;
            border-top-style: groove;
            border-left-style: groove;
            border-right-style: groove;
            border-bottom-style: groove;
            border-top-width: thin;
            border-left-width: thin;
            border-right-width: thin;
            border-bottom-width: thin;
            border-style: none
        }
    </style>
    </head>
    <body id="idbody" onLoad="initPage()">

        <form action="" name="orderForm">
            <div id="loginForm">
                <center>
                    <table>
                        <tr><td><input type="text" id="userid" name="userid" value=""></td></tr>
                        <tr><td><input type="password" id="password" name="password" value=""></td></tr>
                        <tr>
                            <td align="center">
                                <input type="button" name="logins" value="Login System" onclick="login()">
                                <!-- onmouseover="icon_point(this)" -->

                                       <!-- style="border-style: outset; width: 45px; height: 35px; background-image: url('imgs/lock_open.png');background-position:center" -->
                            </td>
                        </tr>
                    </table>
                </center>
            </div>
            <div id="waiting"><center>
                    <table border="0" style="width: 300px; height: 160px">
                        <tr><td align="center"><img src="imgs/loading16.gif" border="0" align="center"></td></tr>
                        <tr><td align="center"><font style="color: gray">Loading...</font></td></tr>
                    </table>
                </center>
            </div>
        </form>

    </body>
</html>

